import 'package:flutter/material.dart';

class GridViewCase extends StatelessWidget {
  const GridViewCase({Key? key}) : super(key: key);

  List<Widget> getChildren() {
    return [1, 2, 3, 4, 5, 6, 7, 9, 10].map((int value) {
      return Container(
        alignment: Alignment.center,
        color: Colors.teal,
        child: Text(
          '第$value个',
          style: const TextStyle(color: Colors.white, fontSize: 30),
        ),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.all(10),
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              // 横轴的数量
              crossAxisCount: 4,
              crossAxisSpacing: 10,
              mainAxisSpacing: 10,
              childAspectRatio: 0.5),
          children: getChildren(),
          // 设置 横向 纵向 空间
        ));
  }
}
